import Qt 4.7

Rectangle {
    id: mainContainer

    width: 640; height: 360
    color: "black"
    state: 'splash'

    signal loginConfirmed

    Image {
        id: initialBackground

        source: "../resources/pixmaps/Splash/Background.png"
        anchors.fill: parent
    }

    Image {
        id: splashMarca

        source: "../resources/pixmaps/Splash/Marca_splash.png"
        anchors.fill: parent

        Behavior on opacity {
            NumberAnimation { duration: 1000 }
        }

        onOpacityChanged: {
            if (splashMarca.opacity == 0)
                mainContainer.state = 'login'
        }
    }

    Timer {
        id: splashTimer

        interval: 4000
        repeat: false

        onTriggered: splashMarca.opacity = 0
    }

    Image {
        id: loginMarca

        source: "../resources/pixmaps/Splash/Login/Marca_login.png"
        anchors.fill: parent

        Behavior on opacity {
            NumberAnimation { duration: 1000 }
        }

    }

    LoginBox {
        id: loginBox

        x: 275; y: 122

        Behavior on opacity {
            NumberAnimation { duration: 1000 }
        }
        onCreateAccountClicked: {
            loginMarca.visible = false;
            loginBox.visible = false;
            newAccountView.visible = true;
        }
        onOkClicked: {
            if (daoManager.login(username,password))
                parent.loginConfirmed();
        }

    }
    NewAccountView {
        id: newAccountView

        anchors.fill: parent
        visible: false

        onCancel: {
            loginMarca.visible = true
            loginBox.visible = true
            newAccountView.visible = false
        }

        onOk: {
            loginMarca.visible = true
            loginBox.visible = true
            newAccountView.visible = false
        }
    }

    states: [
        State {
            name: "splash"

            PropertyChanges { target: initialBackground; opacity: 1 }
            PropertyChanges { target: splashMarca; opacity: 1 }
            PropertyChanges { target: splashTimer; running: true }
            PropertyChanges { target: loginMarca; opacity: 0 }
            PropertyChanges { target: loginBox; opacity: 0 }
        },
        State {
            name: "login"

            PropertyChanges { target: splashMarca; opacity: 0 }
            PropertyChanges { target: splashTimer; running: false }
            PropertyChanges { target: loginMarca; opacity: 1 }
            PropertyChanges { target: loginBox; opacity: 1 }
        }
    ]
}

